import { useState } from "react";

function App() {
  /*
    setState 更新 state 数据是同步更新还是异步更新？
      setCount(count + 1) 是异步更新的
      如果想要数据达到同步更新的效果：
        setCount((count) => {
          return count + 1;
        })
  */

  const [count, setCount] = useState(0);

  const handleClick = () => {
    // setCount(count + 1);
    // console.log(count); // 0
    // setCount(count + 1);
    // console.log(count); // 0
    // setCount(count + 1);
    // console.log(count); // 0

    setCount((count) => {
      return count + 1;
    });
    setCount((count) => {
      return count + 1;
    });
    setCount((count) => {
      return count + 1;
    });
  };

  return (
    <div>
      <button onClick={handleClick}>点击次数：{count}</button>
    </div>
  );
}

export default App;
